/*
 *	This file is part of Lounge-Cast.
 *
 *  Author:  	Markus Moormann
 *	E-mail:  	mmoorman@uni-osnabrueck.de
 *	Copyright:	University of Osnabrueck (Zentrum Virtuos)
 * 	Website:	www.uni-osnabrueck.de
 *	Date:		16.02.2011
 *
 *	Lounge-Cast is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *	Lounge-Cast is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Lounge-Cast.  If not, see <http://www.gnu.org/licenses/>.
 */
package multimedia.model
{
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import flash.system.Capabilities;
	import flash.text.TextFormatAlign;
	
	import multimedia.model.vo.MediaElementVO;
	import multimedia.model.vo.MediaVO;
	import multimedia.model.vo.SlideVO;
	import multimedia.model.vo.TextVO;
	import multimedia.model.vo.VideoVO;
	import multimedia.view.NewsRSSView;
	import multimedia.view.extended.TextArea;
	
	import mx.collections.ArrayCollection;
	import mx.collections.IViewCursor;
	import mx.controls.Label;
	import mx.controls.SWFLoader;
	import mx.logging.targets.TraceTarget;
	
	import org.osmf.elements.DurationElement;
	import org.osmf.elements.SerialElement;
	import org.osmf.elements.TextElement;
	import org.osmf.layout.LayoutMetadata;
	import org.osmf.media.MediaElement;
	import org.osmf.media.MediaFactory;
	import org.osmf.samples.MediaContainerUIComponent;
	
	/**
	 * 	ModelLocator
	 * 
	 *	@author jemden
	 *	@version 1.0
	 */
	[Bindable]
	public class ModelLocator
	{
		//----------------------------------------------------------------------------------------------
		//
		//  Fields
		//
		//----------------------------------------------------------------------------------------------
		
		private static var instance:ModelLocator;
		
		// Main State
		public var mainState:String;
		
		//Preferences State
		public var preferencesState:String;

		// Preferences File
		public static var XML_FILE_NAME:String = "preferences.xml";
		
		// Webservice URL		
		public var url:String;

		// Webservice API-Key
		public var apiKey:String;

		// Player-ID
		public var playerId:String;

		// Startup preferences
		public var fullscreenOnStartup:Boolean;
		
		public var showNewsticker:Boolean;
		
		// Show Debug Information
		public var debug:Boolean = false;
		
		// Log
		public var log:String = "init";
		public var currentMediaTime:String = "00:00";
		
		// Current Video Value Object
		public var currentVideo:VideoVO;
		
		// Current Text Value Object
		public var currentText:TextVO;
		
		// Current Text Value Object
		public var currentSlide:SlideVO;
		
		// Current Caption Set
		public var currentCaptionSet:Array;
		
		// Current Caption Set
		public var currentNewsRSSItems:Array;
		
		// Current Player State
		//public var currentPlayerState:String;
		
		// Current RSSFeed State
		public var rssFeedPlaying:Boolean;
		
		//newsRSS
		public var newsRSS:NewsRSSView;
		
		public var errors:int = 0;
		public var allErrors:int = 0;
		
		public var errorElement:MediaElementVO;
		
		// OSMF
		public var wrapper:MediaContainerUIComponent;
		
		public var background_color:uint;
		
		public var nextEvent:CairngormEvent;
		
		public var currentMediaElement:MediaElement;
		
		public var currentMedia:MediaVO;
		
		public var mediaElements:Array;
		public var counter:uint = 0;
		
		public var captionLabel:TextArea;
		public var captionEnabled:Boolean = false;
		public var mediaFactory:MediaFactory;
		
		public var sourceLabel:Label;
		public var sourceEnabled:Boolean = false;
		
		public var serialElement:SerialElement;
		
		public var traceTarget:TraceTarget;
		
		public var traceLogging:Boolean;
		public var fileLogging:Boolean;
		public var logLevel:Number;
		
		//----------------------------------------------------------------------------------------------
		//
		//  Methods
		//
		//----------------------------------------------------------------------------------------------
		
		public static function getInstance():ModelLocator
		{
			if (instance == null)
				instance = new ModelLocator();
			return instance;
		}
		 
		//----------------------------------------------------------------------------------------------
		//
		//  Constructor
		//
		//----------------------------------------------------------------------------------------------
		
		public function ModelLocator()
		{       
			if (instance != null)
			{
				throw new Error( "ModelLocator: Only one model instance should be instantiated");
			}
			
			errorElement = new MediaElementVO(null, null);
			var textVO:TextVO = new TextVO
			textVO.backgroundColor = 0xffffff;
			textVO.duration = 60 * 1;
			textVO.formatedText = "Aufgrund von Wartungsarbeiten ist das System derzeit außer Betrieb.";
			textVO.title = "Außer Betrieb";
			
			var height:int = Capabilities.screenResolutionY
			var width:int = Capabilities.screenResolutionX;
			
			var text:MediaElement = new DurationElement(textVO.duration,
					new TextElement("<b>" + textVO.title + "</b>\n" + textVO.formatedText, 
						true, 
						TextFormatAlign.LEFT, 
						height * 0.8, 
						width * 0.9));
			var textLayout:LayoutMetadata = new LayoutMetadata();
			text.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, textLayout);
			textLayout.paddingTop = 50;
			textLayout.paddingBottom = 50;
			textLayout.paddingLeft = 50;
			textLayout.paddingRight = 80;
			
			errorElement.mediaElement = text;
			errorElement.media = textVO;
		}
	}
}

 
